 package com.xqzgj.stock.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xqzgj.common.annotation.Log;
import com.xqzgj.common.core.controller.BaseController;
import com.xqzgj.common.core.domain.AjaxResult;
import com.xqzgj.common.enums.BusinessType;
import com.xqzgj.stock.domain.SupplierType;
import com.xqzgj.stock.service.ISupplierTypeService;
import com.xqzgj.common.utils.poi.ExcelUtil;
import com.xqzgj.common.core.page.TableDataInfo;

/**
 * 供应商类型Controller
 * 
 * @author zhoujiam
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/stock/supplier/type")
public class SupplierTypeController extends BaseController {
    @Autowired
    private ISupplierTypeService supplierTypeService;

    /**
     * 查询供应商类型列表
     */
    @PreAuthorize("@ss.hasPermi('stock:supplier:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplierType supplierType) {
        startPage();
        List<SupplierType> list = supplierTypeService.selectSupplierTypeList(supplierType);
        return getDataTable(list);
    }

    /**
     * 导出供应商类型列表
     */
    @PreAuthorize("@ss.hasPermi('stock:supplier:type:export')")
    @Log(title = "供应商类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplierType supplierType) {
        List<SupplierType> list = supplierTypeService.selectSupplierTypeList(supplierType);
        ExcelUtil<SupplierType> util = new ExcelUtil<SupplierType>(SupplierType.class);
        util.exportExcel(response, list, "供应商类型数据");
    }

    /**
     * 获取供应商类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('stock:supplier:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId) {
        return success(supplierTypeService.selectSupplierTypeById(typeId));
    }

    /**
     * 新增供应商类型
     */
    @PreAuthorize("@ss.hasPermi('stock:supplier:type:add')")
    @Log(title = "供应商类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplierType supplierType) {
        return toAjax(supplierTypeService.insertSupplierType(supplierType));
    }

    /**
     * 修改供应商类型
     */
    @PreAuthorize("@ss.hasPermi('stock:supplier:type:edit')")
    @Log(title = "供应商类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierType supplierType) {
        return toAjax(supplierTypeService.updateSupplierType(supplierType));
    }

    /**
     * 删除供应商类型
     */
    @PreAuthorize("@ss.hasPermi('stock:supplier:type:remove')")
    @Log(title = "供应商类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds) {
        return toAjax(supplierTypeService.deleteSupplierTypeByIds(typeIds));
    }
}